<template>
	<view class="content">
		<view v-if="isLogin">
			<image class="headicon" src="../../static/my.png" style="width: 100px;height: 100px;"></image>
			<view class="text-area" v-if="isLogin">
				<text class="title">{{userInfo.name}}</text>
			</view>
		</view>
		<view v-if="!isLogin">
			<image class="headicon" :src="userInfo.icon" style="width: 100px;height: 100px;"></image>
			<view class="text-area">
				<button type="primary" size="mini" @click="toLogin">点击登录</button>
			</view>
		</view>
		<view class="entry-wrapper">
			<view @click="toPage1()">
				<image src="../../static/liuyanzhi.png" mode=""></image>我的留言
			</view>
			<view @click="toPage()">
				<image src="../../static/pinglun.png" mode=""></image>我的评论
			</view>
			<view>
				<image src="../../static/shoucang.png" mode=""></image>我的收藏
			</view>
		</view>
		<view class="button">
			<button type="primary" :disabled="!isLogin" @click="logout">退出</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					userid: null,
					name: '',
					headicon: '',
					nickname: '',
				},
				isLogin: false
			}
		},
		onLoad() {

		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			logout() {
				uni.setStorageSync('userInfo', null)
				this.getUserInfo()

			},
			toLogin() {
				uni.navigateTo({
					url: './login'
				})
			},
			getUserInfo() {
				let userInfo = uni.getStorageSync('userInfo')
				if (userInfo) {
					this.userInfo = userInfo
					this.isLogin = true
					console.log('用户已登录，读取成功');
				} else {
					this.userInfo.name = null
					this.userInfo.nickname = null
					this.userInfo.icon = '../../static/my_normal.png'
					this.isLogin = false
				}
			},
			toPage() {
				uni.navigateTo({
					url: '../message/message'
				})
			},
			toPage1() {
				uni.navigateTo({
					url: '../message/addmessage'
				})
			}
		}
	}
</script>


<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.head {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 100rpx;
		align-self: flex-start;
	}

	.head>image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin-right: 50rpx;
	}

	.head>image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin-right: 50rpx;
	}

	.head>text {
		align-self: 30rpx;
	}

	.entry-wrapper {
		margin-top: 80rpx;
		margin-bottom: 80rpx;
		width: 95%;

	}

	.entry-wrapper>view>image {
		width: 48rpx;
		height: 48rpx;
	}

	.entry-wrapper>view {
		width: 100%;
		height: 3em;
		line-height: 3em;
		border-bottom: 1px solid #CCC;
		text-indent: 1em;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.entry-wrapper>view:first-child {
		border-top: 1px solid #CCC;
	}

	.button {
		width: 95%;
	}
	.text-area {
			display: flex;
			justify-content: center;
		}
</style>